package com.bwie.controller;

import com.bwie.common.domain.request.LoginRequest;
import com.bwie.common.domain.response.JwtResponse;
import com.bwie.common.result.Result;
import com.bwie.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 登录控制层
 *
 * @author <a href="mailto:2891704036@qq.com">zhiyuheng</a>
 * @version 1.0
 * @description: 登录控制层
 * @date 2025/9/9 9:46
 */
@RestController
public class AuthController {

    @Autowired
    private AuthService authService;

    /**
     * 发送验证码
     * @param phone
     * @return
     */
    @GetMapping("sendCode/{phone}")
    public Result sendCode(@PathVariable("phone") String phone){
        authService.sendCode(phone);
        return Result.success();
    }

    /**
     * 登录
     * @param loginRequest
     * @return
     */
    @PostMapping("login")
    public Result login(@RequestBody @Valid LoginRequest loginRequest){
        JwtResponse jwtResponse = authService.login(loginRequest);
        return Result.success(jwtResponse);
    }
}
